package com.wxpay;

import com.wxpay.config.WxpayConfig;
import com.wxpay.common.IServiceRequest;

//微信支付-商户平台 所有的支付操作 https://pay.weixin.qq.com/wiki/doc/api/app/app.php?chapter=8_3
public class PayService {

	// 微信支付-商品平台 下单业务流程: https://pay.weixin.qq.com/wiki/doc/api/app/app.php?chapter=8_3
	//统一下单接口地址(必须用的一个接口)
	public static String UNIFIED_ORDER = "https://api.mch.weixin.qq.com/pay/unifiedorder";
	
	//统一下单接口地址-查询订单 https://pay.weixin.qq.com/wiki/doc/api/app/app.php?chapter=9_2&index=4
	public static String QUERY_ORDER = "https://api.mch.weixin.qq.com/pay/orderquery";
	
	//退款接口地址 申请退款 https://pay.weixin.qq.com/wiki/doc/api/app/app.php?chapter=9_4&index=6
	public static String REFUND_ORDER = "https://api.mch.weixin.qq.com/secapi/pay/refundHavePwd";

	//退款接口查询地址  查询退款  https://pay.weixin.qq.com/wiki/doc/api/app/app.php?chapter=9_5&index=7
	public static String REFUND_QUERY_ORDER = "https://api.mch.weixin.qq.com/pay/refundquery";
	
	//发请求的HTTPS请求器
    private static IServiceRequest serviceRequest;
    
	/**
     * 请求统一下单接口
     * //@param scanPayReqData 这个数据对象里面包含了API要求提交的各种数据字段
     * @return API返回的数据
     * @throws Exception
     */
    @SuppressWarnings("rawtypes")
	public static String request(PayReqData data) throws Exception {
		String responseString = null;
		Class c = Class.forName(WxpayConfig.HttpsRequestClassName);
		serviceRequest = (IServiceRequest)c.newInstance();
		responseString = serviceRequest.sendPostNoSSL(UNIFIED_ORDER, data);
		return responseString;
    }
    
    /**
     * 请求查询订单接口
     * //@param scanPayReqData 这个数据对象里面包含了API要求提交的各种数据字段
     * @return API返回的数据
     * @throws Exception
     */
    @SuppressWarnings("rawtypes")
    public static String queryRequest(PayReqData data) throws Exception {
    	Class c = Class.forName(WxpayConfig.HttpsRequestClassName);
    	serviceRequest = (IServiceRequest)c.newInstance();
    	String responseString = serviceRequest.sendPostNoSSL(QUERY_ORDER, data);
    	return responseString;
    }

    /**
     * 请求退款订单接口
     * //@param scanPayReqData 这个数据对象里面包含了API要求提交的各种数据字段
     * @return API返回的数据
     * @throws Exception
     */
    @SuppressWarnings("rawtypes")
    public static String refund(PayReqRefundData data) throws Exception {
    	Class c = Class.forName(WxpayConfig.HttpsRequestClassName);
    	serviceRequest = (IServiceRequest)c.newInstance();
    	String responseString = serviceRequest.sendPost(REFUND_ORDER, data);
    	return responseString;
    }

    /**
     * 请求退款订单接口
     * //@param scanPayReqData 这个数据对象里面包含了API要求提交的各种数据字段
     * @return API返回的数据
     * @throws Exception
     */
    @SuppressWarnings("rawtypes")
    public static String refundQuery(PayReqRefundQueryData data) throws Exception {
    	Class c = Class.forName(WxpayConfig.HttpsRequestClassName);
    	serviceRequest = (IServiceRequest)c.newInstance();
    	String responseString = serviceRequest.sendPost(REFUND_QUERY_ORDER, data);
    	return responseString;
    }
	
}
